package cn.itcast.hello;



import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

public class Hello {
	
	public void test2(){
		
	}
	
//部署流程定义
	ProcessEngine processEngine=ProcessEngines.getDefaultProcessEngine();

	@Test
	public void deploymentProcessDefinition(){
	Deployment deployment	=processEngine.getRepositoryService()//与流程定义和部署对象关联的
		            .createDeployment()//创建部署对象
		            .name("hello入门")
		            .addClasspathResource("diagrams/Hello.bpmn")
		            .addClasspathResource("diagrams/Hello.png")//一次加载一个文件
		            .deploy();//完成部署
	System.out.println("部署id"+deployment.getId());
	System.out.println("部署名称"+deployment.getName());
	}
	//启动流程实例
	@Test
	public void startProcessInstance(){
	ProcessInstance p1=	processEngine.getRuntimeService()//与正在执行的流程实例和和执行对象相关的service
	                 .startProcessInstanceByKey("hello");//使用流程对应的key启动流程实例，与hello.bpmn中id对应,默认对应最新版本流程使用
	System.out.println(p1.getId());//流程实例id
	System.out.println(p1.getProcessDefinitionId());//流程定义id
	
	}
	//查询当前人的个人任务
	@Test
	public void findMyPersonalTesk(){
			
	List<Task> list=processEngine.getTaskService()//与正在执行的任务相关的service
			                    .createTaskQuery()//创建人物查询对象
			                    .taskAssignee("王五")
			                    .list();
	if(list!=null&&list.size()>=0){
		for(Task task:list){
		System.out.println("任务ID"+task.getId());
		System.out.println("任务名字"+task.getName());
		System.out.println("任务办理人"+task.getAssignee());
		System.out.println("流程实例id"+task.getProcessInstanceId());
		System.out.println("流程定义id"+task.getProcessDefinitionId());
		}	
	}
	}
	//完成我的任务
	@Test
	public void completeMyPersonalTesk(){
		processEngine.getTaskService()
		              .complete("508");
		System.out.println("1");
		
	}	
	
	}
	
	

